<template>
  <a-card style="width: 100%">
    <a-form :form="form">
      <a-row :gutter="48">
        <a-col :sm="{span:24}" :lg="{span:12}">
          <a-form-item
            label="拟录取开始时间"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-date-picker
              :disabledDate="disabledStartDate"
              showTime
              format="YYYY-MM-DD HH:mm:ss"
              v-model="startValue"
              placeholder="请选择时间"
              @openChange="handleStartOpenChange"
            />
          </a-form-item>
        </a-col>
        <a-col :sm="{span:24}" :lg="{span:12}">
          <a-form-item
            label="拟录取结束时间"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}"
          >
            <a-date-picker
              :disabledDate="disabledEndDate"
              showTime
              format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择时间"
              v-model="endValue"
              :open="endOpen"
              @openChange="handleEndOpenChange"
            />
          </a-form-item>
        </a-col>
      </a-row>
      <a-row style="text-align: center" > <a-button type="primary" @click="handleSave(startValue,endValue)">保存</a-button></a-row>
    </a-form>
  </a-card>
</template>
<script>
 import moment from 'moment'
// import { mapState } from 'vuex'

export default {
  name: 'SetDate',
  data () {
    return {
      startValue: null,
      endValue: null,
      endOpen: false
    }
  },
  watch: {
    startValue (val) {
      console.log('startValue', val)
    },
    endValue (val) {
      console.log('endValue', val)
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  created () {
    this.loadData()
  },
  methods: {
    // 计算最低开始时间
    disabledStartDate (startValue) {
      const endValue = this.endValue
      if (!startValue || !endValue) {
        return false
      }
      return startValue.valueOf() > endValue.valueOf()
    },
    // 计算最迟结束时间
    disabledEndDate (endValue) {
      const startValue = this.startValue
      if (!endValue || !startValue) {
        return false
      }
      return startValue.valueOf() >= endValue.valueOf()
    },
    // 开始时间
    handleStartOpenChange (open) {
      if (!open) {
        this.endOpen = true
      }
    },
    // 结束时间
    handleEndOpenChange (open) {
      this.endOpen = open
    },
     // 加载数据
    loadData () {
      this.$api.doctorRecruit.admittedGetId().then(res=>{
        if (res.data){
          this.startValue=res.data.qssj;
          this.endValue=res.data.jssj;
        }
      })
    },
    // 保存时进行时间转换
    getFormateTime(time){
      return moment(time).format('YYYY-MM-DD HH:mm:ss')
    },
    // 保存操作
    handleSave (startValue,endValue) {
      if(this.startValue == null || this.endValue == null){
        this.$message.warning("请选择时间")
        return
      }
      // console.log(this.$changeDate(startValue))
      // startValue=new Date(startValue).format("YYYY-MM-DD HH:mm:ss")
      var params = {'qssj':this.getFormateTime(this.startValue),'jssj':this.getFormateTime(this.endValue)}
      this.$api.doctorRecruit.admittedSetAdd(params).then( res => {
          this.loadData()
          this.$message.success("操作成功")
      })

      // this.$api.doctorRecruit.timeLimitAdd(parms).then(res=>{
      //   if (res.data){
      //
      //   }
      // })

    }
  }
}
</script>
